$.fn.exists = function () {
    return this.length !== 0;
}

$(window).resize(function () {
    if (this.resizeTO) clearTimeout(this.resizeTO);
    this.resizeTO = setTimeout(function () {
        $(this).trigger('resizeEnd');
    }, 500);
});


// Avoid `console` errors in browsers that lack a console.
(function () {
    var method;
    var noop = function noop() {
    };
    var methods = [
        'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
        'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
        'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
        'timeStamp', 'trace', 'warn'
    ];
    var length = methods.length;
    var console = (window.console = window.console || {});

    while (length--) {
        method = methods[length];

        // Only stub undefined methods.
        if (!console[method]) {
            console[method] = noop;
        }
    }
}());

// Place any jQuery/helper plugins in here.


// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function f() {
    log.history = log.history || [];
    log.history.push(arguments);
    if (this.console) {
        var args = arguments, newarr;
        args.callee = args.callee.caller;
        newarr = [].slice.call(args);
        if (typeof console.log === 'object') log.apply.call(console.log, console, newarr); else console.log.apply(console, newarr);
    }
};

// make it safe to use console.log always
(function (a) {
    function b() {
    }

    for (var c = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","), d; !!(d = c.pop());) {
        a[d] = a[d] || b;
    }
})
    (function () {
        try {
            console.log();
            return window.console;
        } catch (a) {
            return (window.console = {});
        }
    }());

/* v1.4 */
/* https://github.com/farinspace/jquery.imgpreload */
if ("undefined" != typeof jQuery) {
    (function (a) {
        a.imgpreload = function (b, c) {
            c = a.extend({}, a.fn.imgpreload.defaults, c instanceof Function ? {all: c} : c);
            if ("string" == typeof b) {
                b = new Array(b)
            }
            var d = new Array;
            a.each(b, function (e, f) {
                var g = new Image;
                var h = f;
                var i = g;
                if ("string" != typeof f) {
                    h = a(f).attr("src");
                    i = f
                }
                a(g).bind("load error", function (e) {
                    d.push(i);
                    a.data(i, "loaded", "error" == e.type ? false : true);
                    if (c.each instanceof Function) {
                        c.each.call(i)
                    }
                    if (d.length >= b.length && c.all instanceof Function) {
                        c.all.call(d)
                    }
                    a(this).unbind("load error")
                });
                g.src = h
            })
        };
        a.fn.imgpreload = function (b) {
            a.imgpreload(this, b);
            return this
        };
        a.fn.imgpreload.defaults = {each: null, all: null}
    })(jQuery)
}

/*!
 jQuery Cookie Plugin v1.2
 https://github.com/carhartl/jquery-cookie

 Copyright 2011, Klaus Hartl
 Dual licensed under the MIT or GPL Version 2 licenses.
 http://www.opensource.org/licenses/mit-license.php
 http://www.opensource.org/licenses/GPL-2.0
 */
(function ($, document, undefined) {
    var pluses = /\+/g;

    function raw(s) {
        return s;
    }

    function decoded(s) {
        return decodeURIComponent(s.replace(pluses, ' '));
    }

    var config = $.cookie = function (key, value, options) {
        if (value !== undefined) {
            options = $.extend({}, config.defaults, options);
            if (value === null) {
                options.expires = -1;
            }
            if (typeof options.expires === 'number') {
                var days = options.expires, t = options.expires = new Date();
                t.setDate(t.getDate() + days);
            }
            value = config.json ? JSON.stringify(value) : String(value);
            return(document.cookie = [encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : ''].join(''));
        }
        var decode = config.raw ? raw : decoded;
        var cookies = document.cookie.split('; ');
        for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) {
            if (decode(parts.shift()) === key) {
                var cookie = decode(parts.join('='));
                return config.json ? JSON.parse(cookie) : cookie;
            }
        }
        return null;
    };
    config.defaults = {};
    $.removeCookie = function (key, options) {
        if ($.cookie(key) !== null) {
            $.cookie(key, null, options);
            return true;
        }
        return false;
    };
})(jQuery, document);


// NON CLASSE PER LA GESTIONE DI FUNZIONI VARIE THNX TO www.uprsg.com
var UTILS = {};
UTILS.debug = true;
UTILS.horizontal = "resize_horizontal";
UTILS.vertical = "resize_vertical";
UTILS.minWidth = 960;
UTILS.minHeight = 610;
UTILS.isIPhone = false;
UTILS.isDevice = false;
UTILS.rootPath = "http://www.studiogusto.com/dev/solasie/";

UTILS.getUserAgent = function () {
    var e = navigator.userAgent;
    var t = {device: e.match(/(iPhone|iPod|iPad)/), iphone: e.match(/(iPhone|iPod)/)};
    if (t.device)UTILS.isDevice = true;
    if (t.iphone)UTILS.isIPhone = true
}

UTILS.getWidth = function () {
    var e = $(window).width();
    if (e < UTILS.minWidth)e = UTILS.minWidth;
    return e
}

UTILS.getHeight = function () {
    var e = $(window).height();
    if (e < UTILS.minHeight)e = UTILS.minHeight;
    return e
}

UTILS.outVariable = function (e) {
    if (UTILS.debug)console.log(e);
}

UTILS.dueCifre = function (e) {
    if (parseInt(e, 10) < 10)e = '0' + e;
    return e;
}

UTILS.css3 = function (property, value) {
}

UTILS.noChache = function ($urlToLoad) {
    return $urlToLoad += '?t=' + new Date().getTime();
}

UTILS.varDump = function (obj) {
    var out = '';
    for (var i in obj) {
        out += i + ": " + obj[i] + "\n";
    }

    UTILS.outVariable('varDump:' + obj);

}

UTILS.getURLParameter = function ($index) {
    var currentLocation = window.location;
    currentLocation = currentLocation.toString();
    console.log('chiamato >>>>>>>>>>>>>>>>' + currentLocation);
    currentLocation = currentLocation.replace('?', '#');
    currentLocation = currentLocation.replace('?', '#');
    currentLocation = currentLocation.replace('_', '#');
    currentLocation = currentLocation.replace('_', '#');
    currentLocation = currentLocation.replace('_', '#');
    currentLocation = currentLocation.replace('_', '#');
    currentLocation = currentLocation.replace('_', '#');
    console.log('chiamato >>>>>>>>>>>>>>>>' + currentLocation);
    currentLocation = currentLocation.split('#');
    return currentLocation[$index];
}